<template>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="index" label="序号" width="100" />
      <el-table-column prop="documentNumber" label="采购退货编号" width="150" />
      <el-table-column prop="documentSubject" label="采购退货主题" width="120" />
      <el-table-column prop="vendorId" label="供应商名称" width="120" />
      <el-table-column prop="projectId" label="关联项目" width="120" />
      <el-table-column prop="returnType" label="退货类别" width="120" />
      <el-table-column prop="num" label="退货数量" width="120" />
      <el-table-column prop="sumMoney" label="退货金额" width="120" />
      <el-table-column prop="returnsPersonnel" label="退货人员" width="120" />
      <el-table-column label="退货日期" width="120">
        <template #default="scope">
          {{ formatDate(scope.row.returnDate) }}
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" min-width="150">
        <template #default="scope">
          <el-button link type="danger" :icon="Delete" size="small" @click="Del(scope.row.extractionDetailsId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  
    <el-pagination v-model:current-page="form.pageIndex" v-model:page-size="form.pageSize" :page-sizes="[15, 20, 25, 30]"
      layout="total, sizes, prev, pager, next, jumper" :total="form.totalCount" @size-change="handleSizeChange"
      @current-change="handleCurrentChange" />
  
  </template>
  
  <script lang="ts" setup>
  import { ref, reactive, onMounted } from 'vue'
  import axios from 'axios'
  import { ElMessage,ElMessageBox } from 'element-plus'
  import { useRouter, useRoute } from 'vue-router'
  import { Wread, Wwrite } from "@/axios/axiosHelper"
  import { Delete, Search, Share, Upload } from '@element-plus/icons-vue'
  import dayjs from 'dayjs'
  
  const router = useRouter()
  
  const tableData = ref([])
  
  const form = reactive({
    pageIndex: 1,
    pageSize: 15,
    totalCount: 0,
    totalPage: 0,
  })
  
  const handleSizeChange = (val: number) => {
    Show();
  }
  const handleCurrentChange = (val: number) => {
    Show();
  }
  
  onMounted(() => {
    Show();
  })
  
  const Show=()=>{
    Wread.get("w2-read/api/ExtractionDetails/QueryExtractionDetails",{
      params: {
        pageIndex: form.pageIndex,
        pageSize: form.pageSize,
      }
    })
    .then(res=>{
        tableData.value = res.data.data;
        form.totalCount = res.data.totalCount;
        form.totalPage = res.data.totalPage;
    })
  }

//   const Edit = (itemizedReturnsId: any) => {
//     router.push({
//       path: '/wang/Extraciton/UpdateExtraciton',
//       query:
//     })
//   }
  
  const Del =(extractionDetailsId:any)=>{
    ElMessageBox.confirm(
      '确定删除吗?',
      'Warning',
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      }
    )
      .then(() => {
        axios.post("https://localhost:7114/api/Extraction/DelExtractionDetails",{
            extractionDetailsId:extractionDetailsId
        })
        .then(res=>{
          if(res.data.code==100){
            ElMessage.success(res.data.msg);
            Show();
          }
          else{
            ElMessage.error(res.data.msg);
            return;
          }
        })
      })
      .catch(() => {
        ElMessage({
          type: 'info',
          message: 'Delete canceled',
        })
      })
  }
  
  const formatDate = (date: string) => {
    return dayjs(date).format('YYYY-MM-DD')
  }
  </script>    